import {requestWeatherData} from '../../../services/common_services';
import { SET_WEATHER_DATA } from "./action_type";

const setWeatherData = (data) => {
  return {
    type: SET_WEATHER_DATA,
    weatherData: data
  }
};

export const getWeatherData = () => {
  return async dispatch =>{
    const weatherData = await requestWeatherData();
    const {currentCity, weather_data} = weatherData;
    const { dayPictureUrl, weather } = weather_data[0];
    dispatch(setWeatherData({ dayPictureUrl, weather,  currentCity}));
  };
};
